/*
==================================================================
* 版权所有 © 2025 CaryXiong
* Copyright (C) 2025 CaryXiong(a1816101108@outlook.com)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
===================================================================
*/

#include<iostream>
#include<string>
using namespace std;

int BF(string data, string key){
    int dataLen = data.length();
    int keyLen = key.length();

    int delta = dataLen - keyLen;
    if(delta < 0) throw "key长度小于data长度";

    for(int i=0; i<=delta; i++){
        for(int j=0; j<keyLen; j++){
            if(data[i+j] != key[j]) break;
            if((data[i+j] == key[j]) && j == keyLen-1) return i+1;
        }
    }

    // cout << dataLen << keyLen;
    return -1;
}



int main(){
    string data = "PythonC++JAVA";
    string key = "C++";
    cout << "查找到该数据位于：" << BF(data, key);

    int test;
    cin >> test;

    return 0;
}